package GameElements;

import java.util.Vector;


//Singleton
public class TileFactory 
{
	private static final TileFactory instance = new TileFactory();
	public static final String[] imgsName={"1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png","10.png","11.png","12.png","13.png","14.png","15.png","16.png","17.png","18.png","19.png","20.png","21.png","22.png","23.png", "24.png","A.png","B.png","C.png","D.png","F.png","F+.png","G.png"}; 
	private static final int[][] link= {
										{1,1,1,  1,1,1,  1,2,1,  1,1,1},
										{1,1,1,  1,1,1,  1,1,1,  1,1,1},
										{1,1,1,  1,1,1,  1,1,1,  1,1,1},		
										{1,1,1,  2,3,4,  4,4,4,  4,3,2},		
										{1,1,1,  2,2,2,  2,2,2,  2,2,2},		
										{1,1,1,  2,2,2,  3,3,3,  2,2,2},		
										{1,1,1,  2,2,2,  3,3,3,  2,2,2},		
										{1,1,1,  2,2,2,  1,1,1,  3,3,3},
										{1,1,1,  2,2,2,  3,3,3,  3,3,3},		
										{1,1,1,  2,3,4,  4,3,2,  2,2,2},		
										{1,1,1,  2,2,2,  2,3,4,  4,3,2},		
										{1,1,1,  2,3,4,  4,5,6,  6,7,2},//*********
										{1,1,1,  2,2,2,  2,2,2,  1,1,1},		
										{1,1,1,  2,2,2,  2,2,2,  1,1,1},		
										{1,1,1,  2,3,4,  4,3,2,  1,1,1},
										{1,1,1,  2,3,4,  4,3,2,  1,1,1},		
										{1,1,1,  1,1,1,  2,2,2,  1,1,1},
										{1,1,1,  1,1,1,  2,2,2,  1,1,1},
										{1,1,1,  1,1,1,  2,3,4,  1,1,1},
										{1,1,1,  1,1,1,  2,3,4,  1,1,1},		
										{1,2,3,  3,3,3,  3,2,1,  1,1,1},		
										{1,1,1,  1,1,1,  1,2,3,  3,2,1},		
										{1,1,1,  2,3,4,  4,5,6,  6,7,2},//********
										{1,2,3,  3,4,5,  5,6,7,  7,8,1},//********
										
										
										{1,1,1,  1,2,3,  3,3,3,  3,2,1},//pour l'extension auberge et cathedrale
										{1,1,1,  1,1,1,  1,1,1,  1,1,1},
										{1,1,1,  2,2,2,  3,3,3,  4,4,4},
										{1,1,1,  1,2,3,  3,3,3,  3,2,1},
										{1,1,1,  2,2,2,  2,2,2,  3,3,3},
										{1,2,3,  4,4,4,  5,2,6,  7,7,7},
										{1,2,3,  3,2,4,  4,2,1,  1,1,1}
									   };
	
	private static final int[][] NESWCB = {
										{Tile.farm, Tile.farm, Tile.street, Tile.farm, Tile.cloister, Tile.no_bouclier},
										{Tile.farm, Tile.farm, Tile.farm, Tile.farm, Tile.cloister, Tile.no_bouclier},
										{Tile.castle, Tile.castle, Tile.castle, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.castle, Tile.street, Tile.farm, Tile.street, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.farm, Tile.farm, Tile.farm, Tile.nothing, Tile.no_bouclier},
										{Tile.farm, Tile.castle, Tile.farm, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.farm, Tile.castle, Tile.farm, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.farm, Tile.castle, Tile.farm, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.castle, Tile.farm, Tile.farm, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.street, Tile.street, Tile.farm, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.farm, Tile.street, Tile.street, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.street, Tile.street, Tile.street, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.farm, Tile.farm, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.castle, Tile.farm, Tile.farm, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.street, Tile.street, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.castle, Tile.street, Tile.street, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.castle, Tile.farm, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.castle, Tile.castle, Tile.farm, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.castle, Tile.castle, Tile.street, Tile.castle, Tile.nothing, Tile.yes_bouclier},
										{Tile.castle, Tile.castle, Tile.street, Tile.castle, Tile.nothing, Tile.no_bouclier},
										{Tile.street, Tile.farm, Tile.street, Tile.farm, Tile.nothing, Tile.no_bouclier},
										{Tile.farm, Tile.farm, Tile.street, Tile.street, Tile.nothing, Tile.no_bouclier},
										{Tile.farm, Tile.street, Tile.street, Tile.street, Tile.nothing, Tile.no_bouclier},
										{Tile.street, Tile.street, Tile.street, Tile.street, Tile.nothing, Tile.no_bouclier},
							
										
										{Tile.farm,Tile.street,Tile.farm,Tile.street,Tile.nothing,Tile.no_bouclier},//pour l'extension cathedrale et auberge****
										{Tile.castle,Tile.castle,Tile.castle,Tile.castle,TileAubCath.cathedral,Tile.no_bouclier},//******
										{Tile.castle,Tile.castle,Tile.castle,Tile.castle,Tile.nothing,Tile.no_bouclier},
										{Tile.farm,Tile.street,Tile.farm,Tile.street,TileAubCath.inn,Tile.no_bouclier},
										{Tile.farm,Tile.farm,Tile.farm,Tile.castle,Tile.nothing,Tile.no_bouclier},
										{Tile.street,Tile.castle,Tile.street,Tile.castle,Tile.nothing,Tile.no_bouclier},
										{Tile.street,Tile.street,Tile.street,Tile.farm,Tile.nothing,Tile.no_bouclier},//*******
									};
	
	
	private TileFactory(){}
	    
	public final static TileFactory getInstance() 
	{
		return instance;
	}
	
	public Vector<Tile> createTile(String imgPath, String imgName, int quantite)
	{
		if(quantite <= 0)
		{
			System.out.println("erreur : la quantité doit etre >0");
			return null;
		}
		int idImg = findImgId(imgName);
		if(idImg == -1)
		{
			System.out.println("tuile " + imgName + " non trouvé");
			return null;
		}
		else
		{
			Vector<Tile> t = new Vector<Tile>();
			for(int i=0; i<quantite; i++)
				t.add(new Tile(imgPath+imgName, NESWCB[idImg], link[idImg]));
			return t;
		}
	}
	
	private int findImgId(String imgName)
	{
		for(int i=0; i<imgsName.length; i++)
		{	
			if(imgName.equals(imgsName[i]))
				return i;
		}
		return -1;
	}
}
